package com.solomon.travel.common.service.impl;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.solomon.travel.common.custom.mapper.AgencyCustomMapper;
import com.solomon.travel.common.mapper.AgencyMapper;
import com.solomon.travel.common.mapper.RouteMapper;
import com.solomon.travel.common.model.Page;
import com.solomon.travel.common.po.Agency;
import com.solomon.travel.common.po.Route;
import com.solomon.travel.common.po.RouteExample;
import com.solomon.travel.common.service.AgencyService;

@Service
public class AgencyServiceImpl implements AgencyService {
	
	@Resource
	private AgencyMapper agencyMapper;
	
	@Resource
	private RouteMapper routeMapper;
	
	@Resource
	private AgencyCustomMapper agencyCustomMapper;

	@Override
	public int add(Agency agency) {
		return agencyMapper.insertSelective(agency);
	}

	@Override
	public int update(Agency agency) {
		return agencyMapper.updateByPrimaryKeySelective(agency);
	}

	@Override
	public int add(Route route) {
		return routeMapper.insertSelective(route);
	}

	@Override
	public int update(Route route) {
		return routeMapper.updateByPrimaryKeySelective(route);
	}

	@Override
	public List<Route> listAgencyRoutes(String agencyId, Page page) {
		return agencyCustomMapper.listByAgency(agencyId, page);
	}

	@Override
	public int countRoutes(String agencyId) {
		RouteExample routeExample = new RouteExample();
		routeExample.createCriteria().andAgencyIdEqualTo(agencyId);
		return routeMapper.countByExample(routeExample);
	}

	@Override
	public Route getById(String routeId) {
		return routeMapper.selectByPrimaryKey(routeId);
	}

	@Override
	public int delete(String routeId) {
		return routeMapper.deleteByPrimaryKey(routeId);
	}
	
}
